/**
 * Created by will on 2017/9/21.
 */
$(function () {
    //引入公共部分
    $("#public-style").load("./easytrip-header.html")
    $("#public-side").load("./easytrip-side.html")
    //侧边栏鼠移入移除事件开始
    $('#public-side').on("mouseover",'.all-sort-list > .item > h3',function(){
        $(this).children('i').addClass('side-active');
        $(this).children('a').addClass('side-active');
        $(this).addClass('side-active');
    })
    $('#public-side').on("mouseout",'.all-sort-list > .item > h3',function(){
        $(this).children('i').removeClass('side-active');
        $(this).children('a').removeClass('side-active');
        $(this).removeClass('side-active');
    })

    $('#public-side').on("mouseover mouseout click",'.all-sort-list > .item',function(event){
        if(event.type == "mouseover"){
            //鼠标悬浮
            var eq = $('.all-sort-list > .item').index(this),				//获取当前滑过是第几个元素
                h = $('.all-sort-list').offset().top,						//获取当前下拉菜单距离窗口多少像素
                s = $(window).scrollTop(),									//获取游览器滚动了多少高度
                i = $(this).offset().top,									//当前元素滑过距离窗口多少像素
                item = $(this).children('.item-list').height(),				//下拉菜单子类内容容器的高度
                sort = $('.all-sort-list').height();						//父类分类列表容器的高度

            if ( item < sort ){												//如果子类的高度小于父类的高度
                if ( eq == 0 ){
                    $(this).children('.item-list').css('top', (i-h));
                } else {
                    $(this).children('.item-list').css('top', (i-h)+1);
                }
            } else {
                if ( s > h ) {												//判断子类的显示位置，如果滚动的高度大于所有分类列表容器的高度
                    if ( i-s > 0 ){											//则 继续判断当前滑过容器的位置 是否有一半超出窗口一半在窗口内显示的Bug,
                        $(this).children('.item-list').css('top', (s-h)+2 );
                    } else {
                        $(this).children('.item-list').css('top', (s-h)-(-(i-s))+2 );
                    }
                } else {
                    $(this).children('.item-list').css('top', 3 );
                }
            }

            $(this).addClass('side-active');
            $(this).children('h3').addClass('side-active');
            $(this).children('h3').children('a').addClass('side-active');
            $(this).children('.item-list').css('display','block');
        }else if(event.type == "mouseout"){
            //鼠标离开
            $(this).removeClass('side-active');
            $(this).children('h3').removeClass('side-active');
            $(this).children('h3').children('a').removeClass('side-active');
            $(this).children('.item-list').css('display','none');
        }
    });
    //系统设置按钮
    $('#public-side').on('mouseover','.usercontrol-btn',function(){
        $('.item-list.systemsub').css("min-width","320px");
        $('.extra-tips').css("display","block");
        $('.extra-tips>.usercontrol').css("display","block");
        $('.extra-tips>.platformcontrol').css("display","none");
    })
    $('#public-side').on('mouseover','.platformcontrol-btn',function(){
        $('.item-list.systemsub').css("min-width","320px");
        $('.extra-tips').css("display","block");
        $('.extra-tips>.platformcontrol').css("display","block");
        $('.extra-tips>.usercontrol').css("display","none");
    })
    //    高级搜索滑入
    $(".hysearch").click(function () {
        $(".hysearchfrom").slideDown(500,function () {
            $('#cancel-btn').click(function () {
                $(".hysearchfrom").slideUp(500,function () {
                });

            })
        })
    })
    $('#cancel-btn').click(function(){
        $(this).css({"background-color":"#45a2ff","color":"#ffffff"})
    })
    $('#cancel-btn').mouseleave(function(){
        $(this).css({"background-color":"#fff","color":"#404040"})
    })
//   input表格点击效果

        $("input").focus(function(){
            var valuecontent=$(this).val();
            $(this).css("border-color","#45a2ff")
            $(this).keydown(function(){
                if($(this).val()==valuecontent){
                    $(this).attr('value','');
                    $(this).css("color","black")
                }
            })

            $(this).blur(function () {
                $(this).css("border-color","#b3b3b3")
                if($(this).val()==''||$(this).val()==valuecontent){
                    $(this).attr('value',valuecontent);
                    $(this).css("color","#999")
                }

            })
        });
//    返回按钮回退上一个页面
    $(".return").click(function () {
        window.history.back()
    })
    $(".cancel").click(function () {
        window.history.back()
    })
    $(".save").click(function () {
        window.history.back()
    })
    $('.button1').click(function(){
        $(this).css({"background-color":"#45a2ff","color":"#ffffff"})
    })
    $('.button1').mouseleave(function(){
        $(this).css({"background-color":"#fff","color":"#404040"})
    })
//    头部方法
//    个人中心
    $('#public-style').on("click",'#headerselectleft-personal',function () {
            $('.easytrip-headerpersonal').slideDown(500);
            $(this).addClass("header-select-active")
    })
    $('#public-style').on("mouseleave",'#headerselectleft-personal',function () {
        $('.easytrip-headerpersonal').css("display","none");
        $('#headerselectleft-personal').removeClass("header-select-active")
    })
    $('#public-style').on("mouseenter",'.easytrip-headerpersonal',function () {
        $('.easytrip-headerpersonal').css("display","block");
    })
    $('#public-style').on("mouseleave",'.easytrip-headerpersonal',function () {
        $('.easytrip-headerpersonal').css("display","none");
        $('.easytrip-selectset').css("background-color","#45a2ff")
    })
//    职能设置
    $('#public-style').on("click",'.easytrip-headerfunction',function () {
        $('.easytrip-function-select').slideDown(500);
        $(this).addClass("header-select-active")
    })
    $('#public-style').on("mouseleave",'.easytrip-headerfunction',function () {
        $('.easytrip-function-select').css("display","none");
        $(this).removeClass("header-select-active")
    })
    $('#public-style').on("mouseenter",'.easytrip-function-select',function () {
        $('.easytrip-function-select').css("display","block");
    })
    $('#public-style').on("mouseleave",'.easytrip-function-select',function () {
        $('.easytrip-function-select').css("display","none");
        $('.easytrip-selectset').css("background-color","#45a2ff")
    })
/*//placeholder兼容性
    $('input, textarea').placeholder();
 */
    /*$('#public-side').on("click",'.all-sort-list >.side-order',function () {
        $('.side-order>h3>s').css("display","none");
    })

    $('#public-side').on("click",'.all-sort-list >.side-order>h3>a',function () {
        $('.side-order>h3>s').css("display","none");
    })*/
    //toggle plugin from caibaojian.com
    $.fn.toggle = function( fn, fn2 ) {
        var args = arguments,guid = fn.guid || $.guid++,i=0,
            toggle = function( event ) {
                var lastToggle = ( $._data( this, "lastToggle" + fn.guid ) || 0 ) % i;
                $._data( this, "lastToggle" + fn.guid, lastToggle + 1 );
                event.preventDefault();
                return args[ lastToggle ].apply( this, arguments ) || false;
            };
        toggle.guid = guid;
        while ( i < args.length ) {
            args[ i++ ].guid = guid;
        }
        return this.click( toggle );
    };
    //面包屑导航
    layui.use('element', function(){
        var element = layui.element; //导航的hover效果、二级菜单等功能，需要依赖element模块
        //监听导航点击
        element.on('nav(demo)', function(elem){
            //console.log(elem)
            layer.msg(elem.text());
        });
    });
})


